<template>
  <div>
    <ul>
      <li v-for="(item,i) in ordereds" :key="i">
        <img :src = "item.imgurl">
        <div class="detail">
          <h3>{{item.name}}</h3>
          <h5>{{item.add}}</h5>
          <h4>价格: {{item.price}}</h4>
        </div>
        <button @click="remove(i)">-</button>
      </li>
    </ul>
  </div>
</template>
<script>
var ordereds = []
export default {
  data () {
    return {
      ordereds: ordereds
    }
  },
  computed: {
  },
  mounted () {
    this.load()
  },
  methods: {
    load () {
      if (ordereds.length !== 0) {
        ordereds = []
      }
      for (var item in this.$store.state.ordered) {
        var name = this.$store.state.ordered[item].name
        var price = this.$store.state.ordered[item].price
        var imgurl = this.$store.state.ordered[item].imgurl
        var add
        if (this.$store.state.ordered[item].add2 === '' && this.$store.state.ordered[item].add3 === '') {
          add = '特殊项：' + this.$store.state.ordered[item].add1 + ',\xa0\xa0\xa0加料：无'
        } else {
          add = '特殊项：' + this.$store.state.ordered[item].add1 + ',\xa0\xa0\xa0加料：' + this.$store.state.ordered[item].add2 + ' \xa0 ' + this.$store.state.ordered[item].add3
        }
        var details = { name: name, add: add, price: price, imgurl: require('@/assets/menupic/' + imgurl) }
        ordereds.push(details)
      }
      this.ordereds = ordereds
      console.log(this.$store.state.ordered)
    },
    remove (i) {
      this.$store.commit('ORDERED_REMOVE', i)
      this.load()
    }
  }
}
</script>

<style scoped>
ul{
  list-style-type: none;
  margin-top: 5px;
  padding-left: 35px;
  list-style-type: none;
}
li img{
  clear: both;
  width: 65px;
  height: 65px;
  margin-top: 5px;
  float: left;
}
.detail{
  float: left;
  width: 70vw;
  margin-left: 10px;
}
.detail h3{
  margin: 0px;
}
.detail h4{
  margin: 0px;
}
.detail h5{
  margin: 0px;
  color: grey;
}
button{
  width: 20px;
  height: 20px;
  float: right;
  margin-right: 20px;
  margin-top: -40px;
  color: white;
  background-color: orange;
  border: none;
  border-radius: 10px;
}
</style>
